﻿using TbShop.Business.Components;
using TbShop.Entity;
using TbShop.Web.Infrastructure.Identity;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TbShop.Web.Helpers
{
    public class AdminHelper
    {
        public static ApplicationUser GetAdminById(string id)
        {
            return GetAllUsers().FirstOrDefault(p => p.Id == id);
        }

        public static ApplicationUser GetAdminByName(string name)
        {
            return GetAllUsers().FirstOrDefault(p => p.UserName == name);
        }

        public static IEnumerable<ApplicationUser> UserDatas = null;

        public static IEnumerable<ApplicationUser> GetAllUsers()
        {
            if (UserDatas == null)
            {
                UserManager<ApplicationUser> UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
                UserDatas = UserManager.Users.ToList();
            }
            return UserDatas;
        }
    }
}